﻿using GraduationProject.Model;
using GraduationProject.Webs.Areas.Admin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace GraduationProject.Webs.Controllers
{
    public class HomeController : BaseController
    {
        //首页
        public ActionResult Index()
        {
            ViewData["UserModel"] = CurrentUser;
            //获取分类标记数据
            using (var conn = new RDBMS.SortList())
            {
                if (conn.TrySelectSortList(out SortList[] Sort, null))
                {

                    ViewData["SortModel"] = Sort.ToList();
                }
            }
            //获取置顶数据
            using (var conn = new RDBMS.Novel())
            {
                if (conn.TrySelectTopNovel(out Novel[] Novels, true))
                {
                    ViewData["TopModel"] = Novels.ToList();
                }
            }
            //获取文章分页数据
            return View();
        }
        /// <summary>
        /// 分页获取文章数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetNovelByPage(int curr, int limit)
        {
            using (var conn = new RDBMS.Novel())
            {
                if (conn.TrySelectNovelByPage(out Novel[] Novels, out int TotalCount, curr, limit))
                {
                    return new NewtonsoftJson(new { code = 0, msg = "成功", count = TotalCount, data = Novels });
                }
            }
            return Json(new { code = 1, msg = "抱歉,暂无数据", count = 0, data = new List<Novel>() });
        }
        public ActionResult HomePage()
        {
            return View();
        }
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";
            return View();
        }
        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";
            return View();
        }

        //地图页面
        public ActionResult MapPage()
        {
            return View();
        }
        /// <summary>
        /// （根据搜素内容）获取景区数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetSortListBySearch(string SearchText)
        {
            SortList[] sortLists;
            decimal XPlace;
            decimal YPlace;
            using (var conn = new RDBMS.SortList())
            {
                if (conn.TryGetSortListBySearch(out sortLists, out XPlace, out YPlace, SearchText))
                {
                    return new NewtonsoftJson(new { code = 0, msg = "成功", XP=XPlace,YP= YPlace, data = sortLists });
                }
            }
            return Json(new { code = 1, msg = "抱歉,暂无数据", count = 0, data = new List<SortList>() });
        }
    }
}